package com.ileaf.java8.gui;

import javax.swing.*;
import java.awt.*;

/**
 * @author Lianlb
 * @date 2019-11-24 19:49
 */
public class Home extends JFrame implements Function {

    private JPanel homePanel;
    private JButton encryptButton;
    private JButton decryptButton;
    private JButton otherButton;
    private JButton logout;
    private JButton doubleButton;

    Home(String title) {
        super(title);
        setContentPane(homePanel);
        setMinimumSize(new Dimension(600, 400));
        setLocation(300, 100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        createUIComponents();
    }

    @Override
    public void createUIComponents() {
        // TODO: place custom component creation code here
        addComponentsAction();
    }

    @Override
    public void addComponentsAction() {
        encryptButton.addActionListener(event -> {
            dispose();
            Encrypt encrypt = new Encrypt("加密");
            encrypt.pack();
            encrypt.setVisible(true);
        });
        decryptButton.addActionListener(event -> {
            dispose();
            Decrypt decrypt = new Decrypt("解密");
            decrypt.pack();
            decrypt.setVisible(true);
        });
        logout.addActionListener(event -> {
            System.exit(0);
        });
        doubleButton.addActionListener(event -> {
            dispose();
            DoubleColorBall colorBall = new DoubleColorBall("双色球模拟");
            colorBall.pack();
            colorBall.setVisible(true);
        });
    }

}
